<template>
	<view class="container">
		<view class="welcome_login">
			欢迎登录
		</view>
		<view class="title">
			延长金石数字化POC移动管理端
		</view>
		<view class="form_login">
			<view class="login_row">
				<view class="icon">
					<image src="/static/POC/icon_user@2x.png"></image>
				</view>
				<view class="login_input">
					<input :style="{color:userName===''?'#C4CEDC':'#333333'}" v-model="userName" type="text"
						placeholder="请输入账号" />
				</view>
			</view>
			<view class="login_row login_row_oth">
				<view class="icon">
					<image src="/static/POC/icon_password@2x (1).png"></image>
				</view>
				<view class="login_input">
					<input :style="{color:password===''?'#C4CEDC':'#333333'}" password v-model="password" type="text"
						placeholder="请输入密码" />
				</view>
			</view>
			<view class="rem_pw_box">
				<u-checkbox v-model="checked">记住密码</u-checkbox>
			</view>
			<view class="submit">
				<u-toast ref="uToast" />
				<u-button  :style="{opacity:disabled?'0.2':'1'}" type="success" hover-class="none" @click="submit">登录</u-button>
			</view>
		</view>

	</view>
</template>

<script>
	import indexColumn from "@/_components/indexColumn.vue"
	import indexData from "@/common/index_data.js"
	import {hex_md5} from "@/utils/md5.js";
	import {
		login_api
	} from "@/service/services.js"

	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		components: {
			indexColumn
		},

		computed: {
			...mapState(['dictionary']),
			disabled(){
				if(this.userName===''||this.password===''){
					return true
				}else{
					return false
				}
			}
			
		},

		data() {
			return {
				checked: false,
				userName: '',
				password: ''
			}
		},

		onReady() {},

		mounted() {
			this.userName = uni.getStorageSync('userName')||''
			this.password = uni.getStorageSync('password')||''
			 if(this.userName!==''&&this.password!=='') this.checked = true
		},

		methods: {
			submit() {
				
				if(this.disabled) return
				if (this.userName === '' || this.password === '') return this.$refs.uToast.show({
					title: '请输入账号密码',
					type: 'default',
					position:'bottom'
				})
				login_api({
					account:this.userName,
					passWord:hex_md5(this.password)
				}).then(res=>{
					console.log(res)
					if(res.code===0){
						uni.setStorageSync('userInfo',res.data);
						uni.setStorageSync('token',res.data.token);
						if(this.checked){
							uni.setStorageSync('userName',this.userName);
							uni.setStorageSync('password',this.password);
							console.log(uni.getStorageSync('userInfo').obj)
						}else{
							uni.removeStorage({
							    key: 'userName',
							    success:()=>{}
							});
							uni.removeStorage({
							    key: 'password',
							    success:()=>{}
							});
						}
						uni.navigateTo({
							url:'/pages/dataView/index'
						})
					}
				})
				
				
				
				
				
			},
			...mapMutations(['setDictionary']),
			onEntryClick(e) {
				let url = e.linkPage + "?";
				let paramMap = e.linkParam;
				Object.keys(paramMap).forEach(function(key) {
					let v = paramMap[key];
					url += key + "=" + v;
					url += "&";
				});

				uni.navigateTo({
					url: url
				})
			},

			requireSelectionDatas() {
				uni.showLoading({
					mask: true
				})
				getDictionary().then((res) => {
					console.log("requireSelectionDatas")
					console.log(res)
					uni.hideLoading()
					if (res.code == 0) {
						this.setDictionary(res.data);
					} else {
						uni.showToast({
							icon: "none",
							title: "关键数据更新失败"
						})
					}
				})
			}

		}
	}
</script>

<style lang="scss" scoped>
	.container {
		position: absolute;
		height: 100%;
		width: 100%;
		background-image: url(/static/POC/pic_bg@2x.png);
		background-repeat: no-repeat;
		background-size: 100% 100%;
		box-sizing: border-box;
		padding: 240upx 64upx;
	}

	.welcome_login {
		font-size: 48upx;
		font-family: PingFangHK-Medium, PingFangHK;
		font-weight: 500;
		color: #00000E;
		line-height: 60upx;
	}

	.title {
		font-size: 28upx;
		font-family: PingFangHK-Regular, PingFangHK;
		font-weight: 400;
		color: #929AA5;
		line-height: 36upx;
	}


	.form_login {
		width: 100%;
		margin-top: 64upx;

		image {
			width: 40upx;
			height: 40upx;
		}
	}

	.login_row {
		width: 100%;
		height: 112upx;
		background: #F5F7F9;
		border-radius: 56upx;
		display: flex;
		align-items: center;
		box-sizing: border-box;
		padding: 36upx 48upx;

		.icon {}

		.login_input {
			width: 75%;
			margin-left: 24upx;
			border-left: 1px solid #C4CEDC;

			input {
				font-size: 28upx;
				font-family: PingFangHK-Regular, PingFangHK;
				font-weight: 400;
				color: #C4CEDC;
				box-sizing: border-box;
				padding: 0 24upx;
			}
		}
	}

	.login_row_oth {
		margin-top: 32upx;
	}

	.rem_pw_box {
		box-sizing: border-box;
		padding: 0 48upx;
		margin-top: 26upx;
	}

	.submit {
		margin-top: 66upx;
	}

	.u-size-default {
		height: 112upx;
		background: linear-gradient(95deg, #299AFD 0%, #065FFD 100%);
		border-radius: 56upx;
		font-size: 32upx;
		font-family: PingFangHK-Medium, PingFangHK;
		font-weight: 500;
		color: #FFFFFF;
	}
</style>
